package saucaca.Adapter;

import java.util.List;

import saucaca.Object.AlbumObject;
import saucaca.Util.AppController;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;

import com.android.volley.toolbox.ImageLoader;
import com.lemon.kenhnhacvn.BaseActivity;
import com.lemon.kenhnhacvn.R;

public class GalleryAlbumAdapter extends BaseAdapter {
	private Context context;
	private List<AlbumObject> albums = null;
	LayoutInflater inflater;
	ImageLoader imageLoader;
	public GalleryAlbumAdapter(Context c,List<AlbumObject> albums) {
		context = c;
		this.inflater = LayoutInflater.from(c);
		this.albums=albums;
	}

	// returns the number of images
	public int getCount() {
		return albums.size();
	}

	// returns the ID of an item
	public Object getItem(int position) {
		return position;
	}

	// returns the ID of an item
	public long getItemId(int position) {
		return position;
	}
	
	public class ViewHolder {
		LinearLayout layout;
		public TextView title;
		public TextView artist;
		public ImageView image;
	}
	// returns an ImageView view
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_album_gridview, null);
			holder.layout = (LinearLayout) convertView.findViewById(R.id.item_album_layout);
			holder.title = (TextView) convertView.findViewById(R.id.custom_view_album_Title);
			holder.artist = (TextView) convertView.findViewById(R.id.custom_view_album_artist);
			holder.image = (ImageView) convertView.findViewById(R.id.custom_view_album_image);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		AlbumObject item=albums.get(position);
		holder.title.setText(item.getTXNAME());
		holder.artist.setText(item.getNAME_SINGERS());
		holder.image.setLayoutParams(new LayoutParams(BaseActivity.linear_params_3.width, BaseActivity.linear_params_3.height));
		try {
			imageLoader=((BaseActivity)context).imageLoader;
		} catch (Exception e) {
			imageLoader=AppController.getInstance().getImageLoader();
		}
		
		imageLoader.get(item.getAVATAR(), ImageLoader.getImageListener(holder.image,
	         R.drawable.ic_default, R.drawable.ic_default));
		
		android.widget.LinearLayout.LayoutParams Params = 
				new android.widget.LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		Params.setMargins(5, 5, 5, 5);
		holder.layout.setLayoutParams(Params);
		return convertView;
	}
}